package com.kinyx.framework.db.sentence.res;

import java.util.List;

import com.kinyx.framework.Configs;
import com.kinyx.framework.annotation.assist.Tester;
import com.kinyx.framework.db.configs.DBConfigs;
import com.kinyx.framework.utils.KArrayUtils;
import com.kinyx.framework.utils.KListUtils;

import lombok.AccessLevel;
import lombok.Getter;

/**
 * 多选匹配型表达式子句
 */
@Tester("com.kinyx.framework.db.sentence.res._Expression_IN_Tester_")
class _Expression_IN extends _Expression {

	/** 参数列表 */
	@Getter(value = AccessLevel.PACKAGE)
	private final String[] params;

	_Expression_IN(final Column column, final boolean in, final String paramsStr) {
		super(column, in ? "IN" : "NOT IN");
		this.params = paramsStr.split(Configs.specialSeparator);
	}

	_Expression_IN(final Column column, final boolean in, final List<String> paramsList) {
		super(column, in ? "IN" : "NOT IN");
		this.params = KListUtils.toStringArray(paramsList);
	}

	_Expression_IN(final Column column, final boolean in, final String[] paramsArr) {
		super(column, in ? "IN" : "NOT IN");
		this.params = paramsArr;
	}

	@Override
	public String getSentence(final DBConfigs configs, final boolean isSQL, final boolean withTableAlias) {
		return String.format("%s (%s)", super.getSentence(configs, isSQL, withTableAlias), KArrayUtils.join(this.params, ", ", (param, index) -> "?"));
	}

	@Override
	public String toString() {
		return super.toString() + String.format(", params: %s", KArrayUtils.toString(this.params));
	}

}
